#!/bin/bash
:<< !
runing environment:
	1. need install gradle environment, version:5.2.1
	2. install java envrionment, version 1.8
	3. android sdk envrioment, android sdk8, android sdk9, you could install android studio, then install messed sdk
	4. system config, or added to project's gradlew file ,export GRADLE_USER_HOME(/home/test/.gradle/),ANDROID_HOME(/home/test/Android/Sdk) envrionment variable
	
notice:
	1. integrated cases need gradle build success, command like: gradlew build, no error,failed message
	2. need do some config, local.properties(sdk.dir=/home/test/Android/Sdk)

python script call this bat format like:
	 /home/share/shellUtils/gradleRunAndroidSingleCase.sh /home/test/java_workspace/okhttp_test_project com.example.hudsonbld.testproject.ExampleInstrumentedTest useAppContext ./logfile.txt ./applog.txt

all command like below:
	./gradlew -Pandroid.testInstrumentationRunnerArguments.class=com.example.hudsonbld.testproject.ExampleInstrumentedTest#useAppContext connectedAndroidTest
	
bat script params:
	1. workspace: where the test project stored
	2. testScriptName: contains all test case's script's name , package name and test file name
	3. testCaseName: test case's name
	4. logFile: execute test log stored to this file
	5. appLogFile: be tested soft's log stored to this file

return:
    0: execute normally
    1: execute unnormally

!


echo show $1,$2,$3,$4,$5
workspace=$1
testScriptName=$2
testCaseName=$3
logFile=$4
appLogFile=$5
echo change workspace to $workspace
cd $workspace

echo clean logcat
adb logcat -c

echo recored logcat log
adb logcat  -b main -v time > $appLogFile 2>&1 &

echo execute android single testCase
./gradlew -Pandroid.testInstrumentationRunnerArguments.class=$testScriptName#$testCaseName connectedAndroidTest > $logFile 2>&1

echo stop app log record
killall adb

echo shell exit with status $?
exit $?






